package com.darren.euc.dao.impl;


import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.jdbc.Work;
import org.springframework.stereotype.Repository;

import com.darren.euc.dao.MeetingroomDao;
import com.darren.euc.entity.Meetingroom;


@Repository
public class MeetingroomDaoImpl extends BaseDaoImpl<Meetingroom, Integer> implements MeetingroomDao {
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Meetingroom> getAll() {
		Session session = sessionFactory.getCurrentSession();	
		return session.createQuery("from Meetingroom where enable=true").list();
	}

	@Override
	public void generateMeetingroomData(Integer days) {
		Session session = sessionFactory.getCurrentSession();	
		session.doWork(new Work() {			
			@Override
			public void execute(Connection connection) throws SQLException {
				// TODO Auto-generated method stub
				CallableStatement  callableStatement = connection.prepareCall("{call usp_generate_meetingroom_records( ? )}");
				callableStatement.setInt(1, days); 
				callableStatement.execute();
			}
		});
	}

	@Override
	public List<Meetingroom> getMeegingroomWithStatus(Integer spaceId, String startDate, String endDate) {
		// TODO Auto-generated method stub
		return null;
	}

}